﻿var CustomerSearch = {};
$(function () {
    var pageUrl = window.location.pathname;
    if (pageUrl.indexOf("public-customer") >= 0 || pageUrl.indexOf("all-customer") >= 0) {
        $("#searchForm").submit(function (e) {
            $.get("/Customer/Get-InquirysCount", $("#searchForm").serialize(), function (data) {
                $("#hidInquirysCount").val(data);
                $("#InquirysCount").text(data);
            });
        });
    }
    $("#moresel").toggle(function () {
        $("#moresearch").show();
        $(".showsel").hide();
        $(".hidsel").show();
    }, function () {
        $("#moresearch").hide();
        $(".showsel").show();
        $(".hidsel").hide();
    });
    //城区数据
    multipleRegionsCheckBox('#txtDistrict', 'hidDistrict', 1, false, ['hidArea', 'hidInquiryStatusKeyId', 'propertyType', 'roomType'], '城区');
    //片区数据Start
    $('#hidDistrict :checkbox[name=chbhidDistrict]').click(function () {
        var districtKeyIds = [];
        $('#hidDistrict :checkbox[name=chbhidDistrict]:checked').each(function () {
            districtKeyIds.push($(this).val());
        });
        if (districtKeyIds.length <= 0) {
            $('#txtArea').val('片区');
        }

        multipleRegionsCheckBox('#txtArea', 'hidArea', 2, districtKeyIds, ['hidDistrict', 'hidInquiryStatusKeyId', 'propertyType', 'roomType'], '片区');
    });
    //片区数据End

    //客户状态 
    var inquiryStatusData = dataBind.getRealDataByType(52);
    multipleCheckBox('#btnInquiryStatusKeyId', 'hidInquiryStatusKeyId', inquiryStatusData, ['hidDistrict', 'hidArea', 'propertyType', 'roomType'], 2, '客户状态');
    //房型数据加载
    multipleCheckBox('#txtPropertyType', 'propertyType', dataBind.getRealDataByType(25), ['hidDistrict', 'hidArea', 'hidInquiryStatusKeyId', 'roomType'], 2, '全部房型');
    

    //楼层数据加载
    multipleCheckBox('#txtHouseFloorKeyIds', 'houseFloorKeyIds', dataBind.getRealDataByType(26), ['hidDistrict', 'hidArea', 'hidInquiryStatusKeyId', 'roomType'], 2, '楼层');
    

    dataBind.bindOption(57, '#selInquiryLevelKeyIds');//客户等级数据
    dataBind.bindOption(45, '#inquiryTradeTypeKeyId');//客源交易类型
    $('#inquiryTradeTypeKeyId').change(function () {
        var tempSelected = $(this).find('option:selected').text();
        var tempSalePrice = $('#spanSalePrice');
        var tempRentPrice = $('#spanRentPrice');
        if (tempSelected == '求租') {
            tempSalePrice.css('display', 'none');
            tempSalePrice.find('input').val('');
            tempRentPrice.css('display', '');
        } else if (tempSelected == '求购') {
            tempSalePrice.css('display', '');
            tempRentPrice.css('display', 'none');
            tempRentPrice.find('input').val('');
        } else if (tempSelected == '租购' || tempSelected == '全部交易') {
            tempSalePrice.css('display', '');
            tempRentPrice.css('display', '');
        } else {
            tempSalePrice.css('display', 'none');
            tempSalePrice.find('input').val('');
            tempRentPrice.css('display', 'none');
            tempRentPrice.find('input').val('');
        }
    });

    //不限条件
    $('#selContact').change(function () {
        $('#txtContactType').val('');
        if ($(this).val() == 'moble') {
            //agencyVerify.nonnegativeIntInput("#txtContactType", false);
            //$('#txtContactType').attr("title","请输入7位以上数字");
        } else if ($(this).val() == 'CustomerName') {
            $('#txtContactType').unbind('keyup');
            $('#txtContactType').unbind('blur');
        } else {

            $('#txtContactType').unbind('keyup');
            $('#txtContactType').unbind('blur');
        }
        if ($('#selContact').val() == "-1") {
            $('#txtContactType').hide();
        }
        else {
            $('#txtContactType').show();
        }
    });

    //表单验证
    agencyVerify.nonnegativeIntInput("input[isint=1]", true);

    $('#btnSubmitSesrch').click(function () {
        //点击提交按钮显示".info-list-other"
        $(".info-list-other").show();
        var temf = $("#txtSalePriceFrom").val();
        var temt = $("#txtSalePriceTo").val();
        if (temf != "" && temt != "") {
            if (Number(temf) > Number(temt)) {
                $("#txtSalePriceFrom").val(temt);
                $("#txtSalePriceTo").val(temf);
            }
        }

        temf = $("#txtRentPriceFrom").val();
        temt = $("#txtRentPriceTo").val();
        if (temf != "" && temt != "") {
            if (Number(temf) > Number(temt)) {
                $("#txtRentPriceFrom").val(temt);
                $("#txtRentPriceTo").val(temf);
            }
        }


    });

    $('#btnClear').click(function () {
        $("#hidArea ul").empty();
        $("#txtContactType").css("display", "none");
        $('#hidDepartmentId3').val('');
        $('#hidUserId').val('');
        $('#spanDateTime').css('display', 'none');
        $("#txtDepartmentName3,#txtEmployeeName3").css("color", "gray");
        var tempIsGraphicList = $("#hidIsGraphicList").val();
        setTimeout(function () { $('#hidIsGraphicList').val(tempIsGraphicList); }, 200);
        $('#spanRentPrice').css('display', '');
        $('#spanSalePrice').css('display', '');

        $("#hidDistrict ul").find("input[type=checkbox]").attr("checked", false);
        $("#hidInquiryStatusKeyId ul").find("input[type=checkbox]").attr("checked", false);
        $('#propertyType input[name=chbpropertyType]').attr("checked", false);
        $('#roomType input[name=chbpropertyType]').attr("checked", false);
        $('#roomType input[type=checkbox]').attr("checked", false);
        $('#houseFloorKeyIds input[type=checkbox]').attr("checked", false);

        //mayu:重置公客池combobox
        $('#publicAccountSelector').combobox('clear');
        $('input.textbox-text.validatebox-text').attr('value', '公客池');
    });

    //mayu:非选项值校验
    $('input.textbox-text.validatebox-text').blur(function () {
        //  获得输入值  
        var inputV = $('#publicAccountSelector').combobox('getText');
        var datas = $('#publicAccountSelector').combobox('getData');
        var size = datas.length;
        if (inputV == "" || size == 0) {
          
            return;
        } else {
            for (var i = 0; i < size; i++) {
                if (inputV === datas[i].text) {
                    return;
                }
            }
            $('#publicAccountSelector').combobox('clear');
            $('input.textbox-text.validatebox-text').attr('value', '公客池');
        }
    });

    $('span.textbox.combo').css('width', '').css('height', '');
    $('span.textbox.combo').attr('class', 'outerSpan textbox combo');
    $('input.textbox-text.validatebox-text').attr('value', '公客池');
    $('input.textbox-text.validatebox-text').css('width', '195px');
    $('a[class="textbox-icon combo-arrow"]').css('height', '26px');

    //搜索日期的显示及隐藏
    if ($('#cmbCustomerDateType').val() == '-1') {
        $('#spanDateTime').css('display', 'none');
    }
    $('#cmbCustomerDateType').change(function () {
        if ($(this).val() == '-1') {
            $('#spanDateTime').css('display', 'none');
            $('#txtDateTimeFrom').val('');
            $('#txtDateTimeTo').val('');
        } else {
            $('#spanDateTime').css('display', '');
            var myDate = new Date();
            var currentDate = myDate.getFullYear() + '-' + (myDate.getMonth() + 1) + '-' + myDate.getDate();
            $('#txtDateTimeTo').val(currentDate);
            if ($(this).val() == "rentExpireDate") {
                $('#txtDateTimeTo').unbind('click');
                $('#txtDateTimeTo').click(function () {
                    WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'txtDateTimeFrom\')}', readOnly: true });
                });
            } else {
                $('#txtDateTimeTo').unbind('click');
                $('#txtDateTimeTo').click(function () {
                    WdatePicker({ dateFmt: 'yyyy-MM-dd', minDate: '#F{$dp.$D(\'txtDateTimeFrom\')}', maxDate: '%y-%M-%d', readOnly: true });
                });

            }
        }
    });

    //盘源归属智能提示Start

    //盘源归属
    var SearchRank = 0;
    if (customerRight.CheckRight("Customer.Inquiry.Search-All")) {
        SearchRank = 1;
    }
    else if (customerRight.CheckRight("Customer.Inquiry.MyDepartment")) {
        SearchRank = 3;
    }
    else if (customerRight.CheckRight("Customer.Inquiry.MySelf")) {
        SearchRank = 4;
    }
    EmployeePrompt.getDepartAndEmployeeByInput('txtDepartmentName3', 'hidDepartmentId3', 'txtEmployeeName3', 'hidUserId', false, 'private', SearchRank, '请输入业务姓名', '请输入部门名称', true);

    //满五年等checkbox显示start
    var PropertyboolTag = [], PropertyboolCalcTag = [];
    for (var k = 0; k < SysParam.length; k++) {
        if (SysParam[k].ParameterType == '58') {
            PropertyboolTag = SysParam[k].Items;
        }
        if (SysParam[k].ParameterType == '62') {
            PropertyboolCalcTag = SysParam[k].Items;
        }
    }
    //客源标签
    for (var i = 0; i < PropertyboolTag.length; i++) {
        $("#propertyboolTag").append("<label><input type='checkbox' name='PropertyboolTag' value='" + PropertyboolTag[i].ItemValue + "' text='" + PropertyboolTag[i].ItemText + "' />" + PropertyboolTag[i].ItemText + "</label>");
    }
    //客源计算标签
    for (var i = 0; i < PropertyboolCalcTag.length; i++) {
        if ($("#hidNeedInquiryExpireTip").length > 0) {
            if ($("#hidNeedInquiryExpireTip").val() == "False" && PropertyboolCalcTag[i].ItemCode == "10") {
            }
            else {
                $("#propertyboolTag").append("<label class='l'><input type='checkbox' name='PropertyboolCalcTag' value='" + PropertyboolCalcTag[i].ItemValue + "' text='" + PropertyboolCalcTag[i].ItemText + "' />" + PropertyboolCalcTag[i].ItemText + "</label>");
            }
        }
    }
    //满五年等checkbox显示End

    //及时搜索  
    $("#propertyboolTag input[name=PropertyboolTag], #propertyboolTag input[name=PropertyboolCalcTag], #IsChannelInquiry,#IsCustomerReferral,#IsAPP,#IsCustomerAction").bind("click", function () {
        $("#searchForm").submit();
    });
    //方便复制客源编号等
    $("#txtContactType").focus(function() {
        $(this).select();
    });
    //浮动的工具栏 yjj添加
    var state1 = true; //存储顶部显示的状态
    $(window).scroll(function () {
        if ($(window).scrollTop() > $("#ajaxPages").offset().top) {
            if (state1) {
                //执行浮动层出现后的代码
                $("#editToolsBox").addClass("float-edit-toos");
                //表头排序
                $('.fixed-div div').find(".fixed-span").unbind("click");
                $('.fixed-div div').find(".fixed-span").click(function () {
                    var resultVal = $(this).attr('callValue');
                    if (resultVal) {
                        $('#hiddenSortValue').val(resultVal);
                        $('#searchForm').submit();
                    }
                });
                //解决全部客源、公客池文字列表，锁定表头出现时，排序样式丢失的问题
                var n = $("#gdIndexCustomerList th").size();
                for (var i = 0; i < n; i++) {
                    $(".fixed-div div").find(".fixed-span").eq(i).find("span").removeClass().addClass($("#gdIndexCustomerList th").eq(i).find("span").attr("class"));
                }

                $(".fixed-div").show();
                $("#gdIndexCustomerList .thead").css("visibility", "hidden");
            }
            state1 = false;
        } else {
            if (!state1) {
                //执行浮动层出现前的代码
                $("#editToolsBox").removeClass("float-edit-toos");
                $(".fixed-div").hide();
                $("#gdIndexCustomerList .thead").css("visibility", "visible");
            }
            state1 = true;
        }
        $(".tab-panel-wrapper").scroll(function () {
            var l = $(".tab-panel-wrapper").scrollLeft();
            $(".fixed-div div").css("margin-left", "-" + l + "px");
        });
    });
});


CustomerSearch.delHiddenValue = function (element) {
    var allInputs = $(element).parent().find('input[type=hidden]');
    allInputs.each(function () {
        $(this).val('');
    });

    var checkboxs = $("#searchForm").find(":checked");
    checkboxs.each(function () {
        $(this).attr("checked", false);
    });
    
};

//是否是点击submit，主要判断是否生成json
CustomerSearch.isSubmit = function (element) {
    $(element).attr("isSubmitValue", "true");
};

//保存搜索条件
CustomerSearch.saveSearchCondition = function (element, saveSearchType) {
    var reqData = {
        "SaveSearchType": saveSearchType,
        "Json": $("#divJson").html()
    };
    //if (reqData.Json.length == 1010) {
    //    //如果等于这个1010错误，就先判断是否是正确的Json格式
    //    if (reqData.Json.indexOf("DistrictNames") > 0 && reqData.Json.indexOf("EstateNames") > 0
    //        && reqData.Json.indexOf("}") > 0) {
    //    }
    //    else {
    //        $.OKDialogAgency('<div class="tc">请选择至少一个搜索条件！</div>');
    //        return;
    //    }
    //}
    $.AjaxAgency("/customer/inquiry-search-criteria-add-ajax", reqData, function (data) {
        if (data.indexOf("ok:") == 0) {
            $(element).css("display", "none");
            $("#spanUsedQuota").css("display", "");
            var tempData = data.split(":")[1];
            $("#strUsedQuotaConut").html(tempData.split("-")[0]);
            $("#spanUsedQuota").attr("leavequota", tempData.split('-')[1]);
            $.OKDialogAgency('<div class="tc">保存成功！</div>');
        } else {
            $.OKDialogAgency('<div class="tc">保存失败！' + data + '</div>');
        }
    });
};

//显示保存搜索条件
CustomerSearch.btnShowSearchCondition = function (element, saveSearchType) {
    var reqData = {
        "SaveSearchType": saveSearchType
    };
    $.AjaxAgency("/customer/inquiry-search-criteria-paged-obtain-ajax", reqData, function (data) {
        if (data.indexOf("#Error*:") == 0) {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        } else if (data == "0") {
            $.OKDialogAgency('<div class="tc">没有数据！</div>');
        } else {
            var tempTextValue = "";
            tempTextValue = CustomerSearch.generateSavedConditionTable(data, saveSearchType);
            $.artDialog({
                id: "dialogShowSearchCondition",
                title: "我的找客条件",
                lock: true,
                width: 600,
                content: tempTextValue
            });
        }
    });
};

//生成保存的搜索条件表格
CustomerSearch.generateSavedConditionTable = function (jsonArray, saveSearchType) {
    var tempTextValue = '<div class="pop-box"><table class="data-table" id="tableSearchCondition"><tbody><tr><th>条件</th><th class="w80">操作</th></tr>';
    var tempInnerTextValue = "";

    for (var i = 0; i < jsonArray.length; i++) {
        if (jsonArray[i].Source == saveSearchType && jsonArray[i].Json) {
            tempTextValue += '<tr id="tr' + jsonArray[i].KeyId + '"><td class="tl"><span class="color-12" style="display:inline-block;width:auto !important;max-width:500px;width:500px;" onclick="CustomerSearch.submitSavedCondition(this);" myjson=\'' + jsonArray[i].Json + '\'>';
            tempInnerTextValue = "";

            var realJson = $.parseJSON(jsonArray[i].Json);
            for (var item in realJson) {
                var itemChsName = CustomerSearch.getJsonChsNameByName(item, saveSearchType);
                if (itemChsName && realJson[item]) {
                    //单选框的情况下到静态js取值
                    if (item == "InquiryLevelKeyId") { //客源等级
                        var value = dataBind.getValueByTypeAndKeyId(57, realJson[item]);
                        if (value) {
                            tempInnerTextValue += '<div><label class="red">' + itemChsName + '：</label>' + value + '</div>';
                        }
                    } else if (item == "InquiryTradeTypeKeyId") { //交易类型
                        var value = dataBind.getValueByTypeAndKeyId(45, realJson[item]);
                        if (value) {
                            tempInnerTextValue += '<div><label class="red">' + itemChsName + '：</label>' + value + '</div>';
                        }
                    } else {
                        tempInnerTextValue += '<div><label class="red">' + itemChsName + '：</label>' + realJson[item] + '</div>';
                    }
                }
            }

            if (tempInnerTextValue != "") {
                tempTextValue += tempInnerTextValue;
            } else {
                tempTextValue += '<div>空搜索条件</div>';
            }

            tempTextValue += '</span></td><td><a onclick="CustomerSearch.delSearchCondition(\'' + jsonArray[i].KeyId + '\',' + saveSearchType + ');">删除</a> ';
            if (jsonArray[i].IsDefault) {
                tempTextValue += '<span keyid="' + jsonArray[i].KeyId + '" type="setdefault"><a onclick="CustomerSearch.cancelDefault(\'' + jsonArray[i].KeyId + '\',this);">取消默认</a></span>';
            }
            else {
                tempTextValue += '<span keyid="' + jsonArray[i].KeyId + '" type="setdefault"><a onclick="CustomerSearch.setDefault(\'' + jsonArray[i].KeyId + '\',this);">设置默认</a></span>';
            }
            tempTextValue += '</td></tr>';
        }
    }

    tempTextValue += '</tbody></table></div>';
    return tempTextValue;
};

//根据Json项英文名与保存搜索类型（通盘房源、全部客源等）获取对应中文名
CustomerSearch.getJsonChsNameByName = function (itemName, saveSearchType) {
    var chsName = "";
    if (saveSearchType == "8") {
        switch (itemName) {
            case "DistrictNames":
                chsName = "城区";
                break;
            case "HouseFloorNames":
                chsName = "楼层";
                break;
            case "AreaNames":
                chsName = "片区";
                break;
            case "InquiryStatusNames":
                chsName = "客源状态";
                break;
            case "FilterType":
                chsName = "";
                break;
            case "CustomerName":
                chsName = "客户姓名";
                break;
            case "Mobile":
                chsName = "手机";
                break;
            case "Tel":
                chsName = "座机";
                break;
            case "CustomerNo":
                chsName = "客户编号";
                break;
            case "HouseTypeNames":
                chsName = "房型";
                break;
            case "InquiryLevelKeyId":
                chsName = "客源等级";
                break;
            case "InquiryTradeTypeKeyId":
                chsName = "交易类型";
                break;
            case "SalePriceFromAndTo":
                chsName = "求购价格";
                break;
            case "RentPriceFromAndTo":
                chsName = "求租价格";
                break;
            case "ChiefDeptName":
                chsName = "客源归属人部门";
                break;
            case "ChiefName":
                chsName = "客源归属人";
                break;
            case "InquiryDateType":
                chsName = "";
                break;
            case "TrustDateFromAndTo":
                chsName = "委托日期";
                break;
            case "LastFollowDateFromAndTo":
                chsName = "最后跟进日期";
                break;
            case "PublicAccountDateFromAndTo":
                chsName = "掉公客日期";
                break;
            case "RentExpireDateFromAndTo":
                chsName = "租期到期日期";
                break;
            case "CreateTimeFromAndTo":
                chsName = "登记日期";
                break;
            case "TakeSeeTimeFromAndTo":
                chsName = "带看日期";
                break;
            default:
                chsName = "";
                break;
        }
    }

    return chsName;
};

//提交保存条件查询数据
CustomerSearch.submitSavedCondition = function (element) {
    $("#btnClear").click();
    var realJson = $.parseJSON($(element).attr("myjson"));
    //城区
    if (realJson.DistrictKeyIds) {
        $("#hidDistrict ul input[name=chbhidDistrict]").each(function () {
            var keyId = $(this).val();
            if ($.inArray(keyId, realJson.DistrictKeyIds) != -1) {
                $(this).attr("checked", "checked");
            }
        });
        $("#txtDistrict").val(realJson.DistrictNames);

        //片区数据加载
        multipleRegionsCheckBox("#txtArea", "hidArea", 2, realJson.DistrictKeyIds, ["hidInquiryStatusKeyId", "propertyType", "roomType", "hidDistrict"], "");
        if (realJson.AreaKeyIds) {
            $("#hidArea ul input[name=chbhidArea]").each(function () {
                var keyId = $(this).val();
                if ($.inArray(keyId, realJson.AreaKeyIds) != -1) {
                    $(this).attr("checked", "checked");
                }
            });
            $("#txtArea").val(realJson.AreaNames);
        }
    }
    //客源状态
    if (realJson.InquiryStatusKeyIds) {
        $("#hidInquiryStatusKeyId ul input[name=chbhidInquiryStatusKeyId]").each(function () {
            var keyId = $(this).val();
            if ($.inArray(keyId, realJson.InquiryStatusKeyIds) != -1) {
                $(this).attr("checked", "checked");
            }
        });
        $("#btnInquiryStatusKeyId").val(realJson.InquiryStatusNames);
    }
    //房型
    if (realJson.HouseTypeKeyIds) {
        $("#propertyType ul input[name=chbpropertyType]").each(function () {
            var keyId = $(this).val();
            if ($.inArray(keyId, realJson.HouseTypeKeyIds) != -1) {
                $(this).attr("checked", "checked");
            }
        });
        $("#txtPropertyType").val(realJson.HouseTypeNames);
    }

    //楼层
    if (realJson.HouseFloorKeyIds) {
        $("#houseFloorKeyIds ul input[name=chbhouseFloorKeyIds]").each(function () {
            var keyId = $(this).val();
            if ($.inArray(keyId, realJson.HouseFloorKeyIds) != -1) {
                $(this).attr("checked", "checked");
            }
        });
        $("#txtHouseFloorKeyIds").val(realJson.HouseFloorNames);
    }

    //不限条件
    if (realJson.FilterType && (realJson.CustomerName || realJson.Mobile || realJson.Tel || realJson.CustomerNo)) {
        $("#selContact").val(realJson.FilterType).change();
        switch (realJson.FilterType) {
            case "CustomerName":
                $("#txtContactType").val(realJson.CustomerName);
                break;
            case "moble":
                $("#txtContactType").val(realJson.Mobile);
                break;
            case "tel":
                $("#txtContactType").val(realJson.Tel);
                break;
            case "CustomerNo":
                $("#txtContactType").val(realJson.CustomerNo);
                break;
            default:
                break;
        }
    }
    //客源等级
    if (realJson.InquiryLevelKeyId) {
        $("#selInquiryLevelKeyIds").val(realJson.InquiryLevelKeyId);
    }
    //交易类型
    if (realJson.InquiryTradeTypeKeyId) {
        $("#inquiryTradeTypeKeyId").val(realJson.InquiryTradeTypeKeyId).change();
    }
    //求购价格
    if (realJson.SalePriceFrom != null) {
        $("#txtSalePriceFrom").val(realJson.SalePriceFrom);
    }
    if (realJson.SalePriceTo != null) {
        $("#txtSalePriceTo").val(realJson.SalePriceTo);
    }
    //求租价格
    if (realJson.RentPriceFrom != null) {
        $("#txtRentPriceFrom").val(realJson.RentPriceFrom);
    }
    if (realJson.RentPriceTo != null) {
        $("#txtRentPriceTo").val(realJson.RentPriceTo);
    }
    //客源归属人部门
    if (realJson.ChiefDeptKeyId) {
        $("#hidDepartmentId3").val(realJson.ChiefDeptKeyId);
        $("#txtDepartmentName3").val(realJson.ChiefDeptName);
        $("#txtDepartmentName3").css("color", "");
    }
    //客源归属人
    if (realJson.ChiefKeyId) {
        $("#hidUserId").val(realJson.ChiefKeyId);
        $("#txtEmployeeName3").val(realJson.ChiefName);
        $("#txtEmployeeName3").css("color", "");
    }
    //不限日期
    if (realJson.InquiryDateType && (realJson.TrustDateFrom || realJson.TrustDateTo || realJson.LastFollowDateFrom || realJson.LastFollowDateTo || realJson.PublicAccountDateFrom || realJson.PublicAccountDateTo || realJson.RentExpireDateFrom || realJson.RentExpireDateTo || realJson.CreateTimeFrom || realJson.CreateTimeTo || realJson.TakeSeeTimeFrom || realJson.TakeSeeTimeTo)) {
        $("#cmbCustomerDateType").val(realJson.InquiryDateType).change();
        switch (realJson.InquiryDateType) {
            case "trustDate":
                if (realJson.TrustDateFrom) {
                    $("#txtDateTimeFrom").val(realJson.TrustDateFrom.split("T")[0]);
                }
                if (realJson.TrustDateTo) {
                    $("#txtDateTimeTo").val(realJson.TrustDateTo.split("T")[0]);
                }
                break;
            case "lastFollowDate":
                if (realJson.LastFollowDateFrom) {
                    $("#txtDateTimeFrom").val(realJson.LastFollowDateFrom.split("T")[0]);
                }
                if (realJson.LastFollowDateTo) {
                    $("#txtDateTimeTo").val(realJson.LastFollowDateTo.split("T")[0]);
                }
                break;
            case "rentExpireDate":
                if (realJson.RentExpireDateFrom) {
                    $("#txtDateTimeFrom").val(realJson.RentExpireDateFrom.split("T")[0]);
                }
                if (realJson.RentExpireDateTo) {
                    $("#txtDateTimeTo").val(realJson.RentExpireDateTo.split("T")[0]);
                }
                break;
            case "CreateTime":
                if (realJson.CreateTimeFrom) {
                    $("#txtDateTimeFrom").val(realJson.CreateTimeFrom.split("T")[0]);
                }
                if (realJson.CreateTimeTo) {
                    $("#txtDateTimeTo").val(realJson.CreateTimeTo.split("T")[0]);
                }
                break;
            case "TakeSeeTime":
                if (realJson.TakeSeeTimeFrom) {
                    $("#txtDateTimeFrom").val(realJson.TakeSeeTimeFrom.split("T")[0]);
                }
                if (realJson.TakeSeeTimeTo) {
                    $("#txtDateTimeTo").val(realJson.TakeSeeTimeTo.split("T")[0]);
                }
                break;
            case "PublicAccountDate":
                if (realJson.PublicAccountDateFrom) {
                    $("#txtDateTimeFrom").val(realJson.PublicAccountDateFrom.split("T")[0]);
                }
                if (realJson.PublicAccountDateTo) {
                    $("#txtDateTimeTo").val(realJson.PublicAccountDateTo.split("T")[0]);
                }
                break;
            default:
                break;
        }
    }

    if (art.dialog.get("dialogShowSearchCondition")) {
        art.dialog.get("dialogShowSearchCondition").close();
    }
    $("#searchForm").submit();
}

//删除保存的搜索条件
CustomerSearch.delSearchCondition = function (keyId, saveSearchType) {
    $.OKCancelDialogAgency('<div class="tc">您确定要删除此条找客条件吗？</div>', "提示", true, function () {
        var reqData = {
            "keyId": keyId,
            "SaveSearchType": saveSearchType
        };
        $.AjaxAgency("/customer/inquiry-search-criteria-batch-remove-ajax", reqData, function (data) {
            if (data.indexOf("ok:") == 0) {
                if (data.split(":")[1] <= 0) {
                    $("#spanUsedQuota").css("display", "none");
                }
                var tempData = data.split(":")[1];
                $("#strUsedQuotaConut").html(tempData.split("-")[0]);
                $("#spanUsedQuota").attr("leavequota", tempData.split("-")[1]);

                $.artDialog({
                    time: 1,
                    content: '<div class="tc">删除成功！</div>'
                });
                $("#tr" + keyId).remove();
                //当保存条件数目为0时，隐藏".info-list-other"
                if ($('#strUsedQuotaConut').html() == "0") {
                    $(".info-list-other").hide();
                }
            } else {
                $.OKDialogAgency('<div class="tc">' + data + '</div>');
            }
        });
        art.dialog({ id: "dialogShowSearchCondition" }).close();
    }, true);
};

//取消设置默认
CustomerSearch.cancelDefault = function (keyId, el) {
    var reqData = {
        "KeyId": keyId
    };
    $.AjaxAgency('/customer/inquiry-default-search-criteria-cancel-ajax', reqData, function (data) {
        if (data == "ok") {
            $(el).parent().html('<a onclick="CustomerSearch.setDefault(\'' + keyId + '\',this);">设置默认</a>');
        } else {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        }
    });
}

//设置默认
CustomerSearch.setDefault = function (keyId, el) {
    var temspan = $(el).parent()[0];
    var reqData = {
        "KeyId": keyId
    };
    $.AjaxAgency("/customer/inquiry-default-search-criteria-ajax", reqData, function (data) {
        if (data == "ok") {
            $("#tableSearchCondition span[type=setdefault]").each(function () {
                if (this == temspan) {
                    $(this).html('<a onclick="CustomerSearch.cancelDefault(\'' + keyId + '\',this);">取消默认</a>')
                }
                else if ($(this).text() == "取消默认") {
                    $(this).html('<a onclick="CustomerSearch.setDefault(\'' + $(this).attr("keyid") + '\',this);">设置默认</a>');
                }
            });
        } else {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        }
    });
}